package com.electrictorch;

import android.app.Activity;
import android.jb.electrictorch.FlashController;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;

import com.example.ht380d4G_jar_demo.R;

public class FlashActivity extends Activity {

	private ToggleButton btn;
	private boolean isOn;
	private FlashController flashController;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.led_light);
		
		flashController.getInstance().power("1");
		btn = (ToggleButton) findViewById(R.id.led_light_btn);
		btn.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				try {
					if (isChecked) {
						flashController.getInstance().power("1");
					} else {
						flashController.getInstance().power("0");
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		});
	}

	

	@Override
	protected void onDestroy() {
		super.onDestroy();
		flashController.getInstance().power("0");	
	}
}
